<UserControl x:Class="ConverterSystems.Workstation.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:Data="clr-namespace:ConverterSystems.Workstation.Data"
             xmlns:cs="http://schemas.convertersystems.com/workstation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:infr="clr-namespace:ConverterSystems.Workstation.Infrastructure"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:opcua="clr-namespace:Opc.Ua;assembly=Opc.Ua.Core"
             xmlns:v="clr-namespace:ConverterSystems.Workstation.Views"
             xmlns:vm="clr-namespace:ConverterSystems.Workstation.ViewModels"
             d:DataContext="{d:DesignInstance Type={x:Type vm:MainViewModel}}"
             d:DesignHeight="600"
             d:DesignWidth="800"
             mc:Ignorable="d">

    <UserControl.Resources>
        <Data:UtcToLocalStringConverter x:Key="UtcToLocalStringConverter" />
        <!--  template for event display message  -->
        <DataTemplate DataType="{x:Type opcua:EventFieldList}">
            <Grid Background="{DynamicResource AccentColorBrush}" TextElement.Foreground="{DynamicResource AccentSelectedColorBrush}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <!--  event time  -->
                <TextBlock Margin="5" Text="{Binding EventFields[0].Value, Converter={StaticResource UtcToLocalStringConverter}, ConverterParameter=yyyy-MM-dd HH:mm:ss}" />
                <!--  event message  -->
                <TextBlock Grid.Column="1"
                           Margin="5"
                           Text="{Binding EventFields[1].Value}" />
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <!--  layout for MainView consists of robot on left and control panel on right  -->
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <v:RobotView />
        <!--  placed canvas on top of robot so i can layout some ui  -->
        <Canvas>
            <StackPanel Orientation="Horizontal">
                <!--  naviagation  -->
                <Button Command="NavigationCommands.GoToPage"
                        CommandParameter="ConverterSystems.Workstation.Views.DetailView"
                        Content="{Binding Source={Localization:Translate Word=Details}}" />
            </StackPanel>
            <!--  event display  -->
            <ContentControl Canvas.Top="35" Content="{Binding Robot1, Mode=OneWay, NotifyOnTargetUpdated=True}">
                <ContentControl.Triggers>
                    <EventTrigger RoutedEvent="Binding.TargetUpdated">
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity">
                                    <EasingDoubleKeyFrame KeyTime="0" Value="0" />
                                    <EasingDoubleKeyFrame KeyTime="0:0:0.25" Value="1" />
                                    <EasingDoubleKeyFrame KeyTime="0:0:4" Value="1" />
                                    <EasingDoubleKeyFrame KeyTime="0:0:5" Value="0" />
                                </DoubleAnimationUsingKeyFrames>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </ContentControl.Triggers>
            </ContentControl>
        </Canvas>
        <v:ControlPanelView Grid.Column="1" />
    </Grid>
</UserControl>
